﻿using System;
using System.Collections.Generic;
using System.Linq;
using GarageManagement.Data.Infrastructure;
using GarageManagement.Domain.Model;
using GarageManagement.Domain.Repository.Contracts;
using GarageManagement.Domain.Service.Contracts;

namespace GarageManagement.Domain.Service.Customers
{
    public class CustomerService : ICustomerService
    {
        private readonly ICustomerRepository customerRepository;
        private readonly IUnitOfWork unitOfWork;

        public CustomerService(ICustomerRepository customerRepository, IUnitOfWork unitOfWork)
        {
            this.customerRepository = customerRepository;
            this.unitOfWork = unitOfWork;
        }

        public IList<Customer> GetCustomers()
        {
            return customerRepository.GetAll().ToList();
        }

        public Customer AddCustomer(Customer customer)
        {
            var createdCustomer = customerRepository.Add(customer);
            unitOfWork.Commit();

            return createdCustomer;
        }

        public Customer GetCustomerById(Guid customerId)
        {
            return customerRepository.GetById(customerId);
        }
    }
}
